//show properties
function fpf_showprop(compType, type) {
	//console.debug("fpf_showprop compType="+compType+" type="+type);
	var ts = new Date();
	//fl.propCell.expand();
	if (!fmdc.grid_prop) {
		fpf_initPropGridLayout();
	} else {
		//fmdc.grid_prop.clearAll();
		fpf_initPropGridLayout();
	}
	if (!fldmeta_prop[compType] || !fldmeta_prop[compType][type]) {
		return;
	}
	fmdc.proptemp = {"compType" : compType, "type" : type};
	fl.curComp.compType = compType;
	fl.curComp.type = type;
	fpf_parsePropsByType(compType, type);
	fmdc.grid_prop.enableValidation(true, true);
	//fmdc.isEditor && fpf_enableApply(fldmeta_prop[compType][type].onApply);
	//bind grid events
	fpf_bindGridEvents(fldmeta_prop[compType][type].propDhxGridEvents);
	//set existing data
	fpf_loadExisting(fl.curComp.id);
	//init config data if it's first time init
	/*MyUtilJs.isEmpty(fl.curflow.bpmnConfig[fl.curComp.id]) && */fpf_collectValues();
	//fmdc.grid_prop.expandAll();
	if(!fl.isloading && fl.propCell.isCollapsed()) {
		fl.propCell.setWidth(fl.propcell_width);
		//fl.propCell.expand();
	}
	//记录需要验证的属性
	fl.curflow.bpmnConfig[fl.curComp.id]["validateProperties"] = fmdc.grid_prop.getAllRowIds();
	var te = new Date();
	//console.debug("fpf_showprop ellapsed------------------"+(te.getTime() - ts.getTime())+" milliseconds.");
}

//hide element properties
function fpf_hide_elemprop() {
	fmdc.autohideprop && fpf_clear_elemprop() && fl.propCell.collapse();
}

//init properties grid
function fpf_initPropGridLayout() {
	fmdc.grid_prop && fmdc.grid_prop.destructor && fmdc.grid_prop.destructor();
	fmdc.grid_prop=null;
	fmdc.grid_prop = fl.propCell.attachGrid();
	fmdc.grid_prop.isEditor = typeof(flbpmn_canChangeProps)=='function' ? flbpmn_canChangeProps(getIORegistedElem(fl.curComp.id)) : flvar.isEditor;
	fldmeta_prop.gridconf.treeIconPath && fmdc.grid_prop.setIconPath(fldmeta_prop.gridconf.treeIconPath);
	fldmeta_prop.gridconf.treeImagePath && fmdc.grid_prop.setImagePath(fldmeta_prop.gridconf.treeImagePath);
	fldmeta_prop.gridconf.extIconPath && (fmdc.grid_prop.extIconPath = fldmeta_prop.gridconf.extIconPath);
	fldmeta_prop.gridconf.header && fmdc.grid_prop.setHeader(fldmeta_prop.gridconf.header);
	fldmeta_prop.gridconf.subHeader && fmdc.grid_prop.attachHeader(fldmeta_prop.gridconf.subHeader);
	fldmeta_prop.gridconf.colType && fmdc.grid_prop.setColTypes(fldmeta_prop.gridconf.colType);
	fldmeta_prop.gridconf.colIds && fmdc.grid_prop.setColumnIds(fldmeta_prop.gridconf.colIds);
	fldmeta_prop.gridconf.colAlign && fmdc.grid_prop.setColAlign(fldmeta_prop.gridconf.colAlign);
	fldmeta_prop.gridconf.colVAlign && fmdc.grid_prop.setColVAlign(fldmeta_prop.gridconf.colVAlign);
	fldmeta_prop.gridconf.colSorting && fmdc.grid_prop.setColSorting(fldmeta_prop.gridconf.colSorting);
	fldmeta_prop.gridconf.colMinWidth && fmdc.grid_prop.setColumnMinWidth(fldmeta_prop.gridconf.colMinWidth);
	fldmeta_prop.gridconf.colInitWidth && fmdc.grid_prop.setInitWidths(fldmeta_prop.gridconf.colInitWidth);
	fldmeta_prop.gridconf.resize && fmdc.grid_prop.enableResizing(fldmeta_prop.gridconf.resize);
	fldmeta_prop.gridconf.visibile && fmdc.grid_prop.setColumnsVisibility(fldmeta_prop.gridconf.visibile);
	fldmeta_prop.gridconf.isTreeGrid && fmdc.grid_prop.enableTreeCellEdit(false);
	fldmeta_prop.gridconf.colColor && fmdc.grid_prop.setColumnColor(fldmeta_prop.gridconf.colColor);
	fldmeta_prop.gridconf.enableTooltips && fmdc.grid_prop.enableTooltips(fldmeta_prop.gridconf.enableTooltips);
	fmdc.grid_prop.enableMultiselect(false);//单选
	fmdc.grid_prop.enableMarkedCells(true);
	fmdc.grid_prop.enableAlterCss("grid_even_row","grid_odd_row");
	fmdc.grid_prop.enableEditEvents(fmdc.grid_prop.isEditor,false,false);
	fmdc.grid_prop.setEditable(fmdc.grid_prop.isEditor);
	fmdc.grid_prop.setSkin(dhx_skin);//set grid skin
	//fmdc.grid_prop.enableTreeGridLines(true);
	fmdc.grid_prop.init();
}

//hide element properties
function fpf_clear_elemprop() {
	//fl.propCell.attachHTMLString('');
	fmdc.grid_prop.clearAll();
	fpf_unbindGridEvents();
	fmdc.proptemp = null;
}

//parse element properties config
function fpf_parsePropsByType(compType, type) {
	
	//parse include properties
	//console.debug("compType="+compType+" type="+type);
	if (fldmeta_prop[compType][type]["includes-properties"]) {
		for (var i in fldmeta_prop[compType][type]["includes-properties"]) {
			//splitter row
			fpf_addTipRow("tiprow_"+i, eval("fmd_i18n_prop_tip_"+i));
			if (fldmeta_prop[compType][type]["includes-properties"][i]) {
				for (var id in fldmeta_prop[compType][type]["includes-properties"][i]) {
					fpf_parsePropByCellType(0, id, fldmeta_prop[compType][type]["includes-properties"][i][id]);
				}
			}
		}
	}
	//parse specific properties
	if (fldmeta_prop[compType][type].properties) {
		//splitter row
		fpf_addTipRow("tiprow_specific", fmd_i18n_prop_tip_specific);
		for (var id in fldmeta_prop[compType][type].properties) {
			fpf_parsePropByCellType(0, id, fldmeta_prop[compType][type].properties[id]);
		}
	}
	
	//abandon properties 检查是否有需要去掉的属性
	var abdp = fldmeta_prop[compType][type]["abandon-properties"];
	if (abdp && typeof(abdp)=='function') {
		abdp = abdp();
	}
	if (abdp && abdp.length) {
		for (var i in abdp) {
			fmdc.grid_prop.deleteRow(abdp[i]);
		}
	}
	
	//====styles
	
	//splitter row
	fpf_addTipRow("tiprow_styles", fmd_i18n_prop_tip_customstyle);
	//!fmdc.advancedview && fmdc.grid_prop.setRowHidden("tiprow_styles", true);
	
	//parse includes styles
	if (fldmeta_prop[compType][type]["includes-styles"]) {
		for (var i in fldmeta_prop[compType][type]["includes-styles"]) {
			if (fldmeta_prop[compType][type]["includes-styles"][i]) {
				for (var id in fldmeta_prop[compType][type]["includes-styles"][i]) {
					fpf_parseStyleByCellType(0, id, fldmeta_prop[compType][type]["includes-styles"][i][id]);
				}
			}
		}
	}
	
	//parse specific styles
	if (fldmeta_prop[compType][type].styles) {
		for (var id in fldmeta_prop[compType][type].styles) {
			fpf_parseStyleByCellType(0, id, fldmeta_prop[compType][type].styles[id]);
		}
	}
	
	//abandon styles 检查是否有需要去掉的样式属性
	if (fldmeta_prop[compType][type]["abandon-styles"] && fldmeta_prop[compType][type]["abandon-styles"].length) {
		for (var i in fldmeta_prop[compType][type]["abandon-styles"]) {
			fmdc.grid_prop.deleteRow(fldmeta_prop[compType][type]["abandon-styles"][i]);
		}
	}
	
	//remove last row if it's tip row 如果最后一行为分割提示行，去掉
	var rn = fmdc.grid_prop.getRowsNum();
	if (rn>0) {
		var prid = fmdc.grid_prop.getRowId(rn-1);
		if (prid && fmdc.grid_prop.getRowAttribute(prid, "isTip")) {
			fmdc.grid_prop.deleteRow(prid);
		}
	}
	
}

//parse cellType
function fpf_parsePropByCellType(pid, id, propconf, hide) {
	//console.debug("pid="+pid+" id:"+id+" propconf="+JSON.stringify(propconf));
	//var ts = new Date();
	//如果属性已存在则不需要添加
	if(-1 != fmdc.grid_prop.getRowIndex(id)) {
		return;
	}
	if (typeof(propconf)=='function') {//如果属性为function格式，采用返回值
		propconf = propconf();
	}
	var defaultVal = null;
	var imgName = propconf.img ? propconf.img : "property.png";
	if (propconf.value) {
		if (typeof(propconf.value)=='function') {//from function
			defaultVal = propconf.value();//如果值为function格式，采用返回值
			//update from function every time
//			fpf_updateValue(id, defaultVal);
		} else if (propconf.value["fromattr"]!=undefined) {//from attribute
			defaultVal = fl.curComp[propconf.value["fromattr"]];// || propconf.value["default"];
			//update from attribute every time
//			fpf_updateValue(id, defaultVal);
		} else if (propconf.value["default"]!=undefined) {//default value
			defaultVal = propconf.value["default"];
		}
	}
	//init value if it does not exist
	if(fl.curflow.bpmnConfig[fl.curComp.id][id]===undefined) {
		fl.curflow.bpmnConfig[fl.curComp.id][id] = defaultVal;
		fpf_updateValue(id, defaultVal);
	} else {
		defaultVal = fl.curflow.bpmnConfig[fl.curComp.id][id];
	}
	
	//propconf.value?(propconf.value["default"]!=undefined)?propconf.value["default"]:"":"";
	//console.debug(propconf.name+" default value:"+defaultVal+"  afterProperty="+propconf.afterProperty);
	var namelabel = propconf.name;
	if (typeof(namelabel)=='function') {//如果属性名称为function格式，采用返回值
		namelabel = propconf.name();
	}
	//是否加星号
	if (propconf.asterisk) {
		namelabel += '<span style="color:red">*</span>';
	}
	
	//add row
	if (propconf.afterProperty) {
		fmdc.grid_prop.addRowAfter(id, 
				["&nbsp;"+namelabel, null],
				propconf.afterProperty);
	} else {
		fmdc.grid_prop.addRow(id, ["&nbsp;"+namelabel, null], null, pid, "blank.gif");
	}
	//add row attribute displayOnly 有“仅显示”标识的属性
	propconf.displayOnly && fmdc.grid_prop.setRowAttribute(id, "displayOnly", true);
	//set image
	fmdc.grid_prop.cells(id, fldmeta_prop.gridconf.idx.prop).setImage(fmdc.grid_prop.extIconPath+imgName);
	
	//set excel type
	//console.debug(id+"="+fldmeta_prop.gridconf.idx.value+"="+(propconf.cellType || "ed"));
	if (propconf.cellType) {
		if (typeof(propconf.cellType)=="string") {//类型为string则直接使用
			fmdc.grid_prop.setCellExcellType(id, fldmeta_prop.gridconf.idx.value, propconf.cellType || "ed");
			"ro"==propconf.cellType && fmdc.grid_prop.cells(id, fldmeta_prop.gridconf.idx.value).setBgColor("#F8F8F8");
		} else if (typeof(propconf.cellType)=="object") {//类型为object，判断type子属性
			if ("coro"==propconf.cellType.type) {//只读下拉列表
				var options1 = typeof(propconf.cellType.options)=='function' ? propconf.cellType.options() 
						: (typeof(propconf.cellType.options)=="string" ? eval(propconf.cellType.options) : propconf.cellType.options);
				if (propconf.cellType.readOnly) {
					fmdc.grid_prop.setCellExcellType(id, fldmeta_prop.gridconf.idx.value, "rocoro");
					fmdc.grid_prop.cells(id, fldmeta_prop.gridconf.idx.value).setOptions(options1);
					propconf.cellType.optionWidth && fmdc.grid_prop.cells(id, fldmeta_prop.gridconf.idx.value).setOptionWidth(propconf.cellType.optionWidth);
				} else {
					fmdc.grid_prop.grid_bindCombo(id, 
							fldmeta_prop.gridconf.idx.value, 
							options1, 
							{"comboSize":10, "comboWidth":propconf.cellType.optionWidth || 160}, 
							defaultVal);
				}
			} else if ("btnex"==propconf.cellType.type) {//弹出式选择框
				fmdc.grid_prop.setCellExcellType(id, fldmeta_prop.gridconf.idx.value, propconf.cellType.type);
			} else if ("colist"==propconf.cellType.type) {//多选列表
				fmdc.grid_prop.setCellExcellType(id, fldmeta_prop.gridconf.idx.value, propconf.cellType.type);
			} else {//其他
				fmdc.grid_prop.setCellExcellType(id, fldmeta_prop.gridconf.idx.value, propconf.cellType.type);
			}
			//set configs if has, some excel type has setConfig function
			propconf.cellType.config && fmdc.grid_prop.cells(id, fldmeta_prop.gridconf.idx.value).setConfig && fmdc.grid_prop.cells(id, fldmeta_prop.gridconf.idx.value).setConfig(propconf.cellType.config);
		}
	}
	//set validate if has
	propconf.validator && typeof(propconf.validator)=='string' && fmdc.grid_prop.cells(id, fldmeta_prop.gridconf.idx.value).setAttribute("validate", propconf.validator);
	//set configs if has, some excel type has setConfig function
	propconf.config && fmdc.grid_prop.cells(id, fldmeta_prop.gridconf.idx.value).setConfig && fmdc.grid_prop.cells(id, fldmeta_prop.gridconf.idx.value).setConfig(propconf.config);
	
	//set value
	fmdc.grid_prop.cells(id, fldmeta_prop.gridconf.idx.value).setValue(defaultVal);
	
	//add sub 属性的子属性
	if (propconf.sub) {
		for (var sid in propconf.sub) {
			fpf_parsePropByCellType(id, sid, propconf.sub[sid]);
		}
		fmdc.grid_prop.openItem(id);
	}
	
	//add conditional-sub and hide 属性的条件子属性
	if (propconf["conditional-sub"]) {
		for (var sid in propconf["conditional-sub"]) {
			for (var ssid in propconf["conditional-sub"][sid]) {
				fpf_parsePropByCellType(id, ssid, propconf["conditional-sub"][sid][ssid], true);
			}
		}
		//fmdc.grid_prop.cells(id, fldmeta_prop.gridconf.idx.prop).cell.firstChild.firstChild.style.visibility="hidden";
	}
	
	//set tooltip
	propconf.tooltip && $(fmdc.grid_prop.cells(id, fldmeta_prop.gridconf.idx.prop).cell).find("div:nth-child(1)").attr("original-title", propconf.tooltip).tipsy({gravity: 'e'});
	//set row hidden
	//override hide from propconf
	if (typeof(propconf.hide)=='function') {
		hide = hide || propconf.hide();
	} else {
		propconf.hide && (hide=true);
	}
	hide && fmdc.grid_prop.setRowHidden(id, true);
	//var te = new Date();
	//console.debug(id+"---------"+(te.getTime() - ts.getTime()));
}

//parse styles by cellType
function fpf_parseStyleByCellType(pid, id, propconf, hide) {
	//console.debug("pid="+pid+" id:"+id+" propconf="+JSON.stringify(propconf));
	//var ts = new Date();
	//如果属性已存在则不需要添加
	if(-1 != fmdc.grid_prop.getRowIndex(id)) {
		return;
	}
	if (typeof(propconf)=='function') {
		propconf = propconf();
	}
	var defaultVal = null;
	var imgName = propconf.img ? propconf.img : "property.png";
	if (propconf.value) {
		if (typeof(propconf.value)=='function') {//from function
			defaultVal = propconf.value();
			//update from function every time
//			fpf_updateValue(id, defaultVal);
		} else if (propconf.value["fromattr"]!=undefined) {//from attribute
			defaultVal = fl.curComp[propconf.value["fromattr"]];// || propconf.value["default"];
			//update from attribute every time
//			fpf_updateValue(id, defaultVal);
		} else if (propconf.value["default"]!=undefined) {//default value
			defaultVal = propconf.value["default"];
		}
	}
	//init value if it does not exist
	if(fl.curflow.bpmnConfig[fl.curComp.id][id]===undefined) {
		fl.curflow.bpmnConfig[fl.curComp.id][id] = defaultVal;
		fpf_updateValue(id, defaultVal);
	} else {
		defaultVal = fl.curflow.bpmnConfig[fl.curComp.id][id];
	}
	
	//propconf.value?(propconf.value["default"]!=undefined)?propconf.value["default"]:"":"";
	//console.debug(propconf.name+" default value:"+defaultVal+"  afterProperty="+propconf.afterProperty);
	var namelabel = propconf.name;
	if (typeof(namelabel)=='function') {
		namelabel = propconf.name();
	}
	
	//add row
	if (propconf.afterProperty) {
		fmdc.grid_prop.addRowAfter(id, 
				[namelabel, null],
				propconf.afterProperty);
	} else {
		fmdc.grid_prop.addRow(id, ["&nbsp;"+namelabel, null], null, pid, "blank.gif");
	}
	//add row attribute displayOnly
	propconf.displayOnly && fmdc.grid_prop.setRowAttribute(id, "displayOnly", true);
	//set image
	fmdc.grid_prop.cells(id, fldmeta_prop.gridconf.idx.prop).setImage(fmdc.grid_prop.extIconPath+imgName);
	
	//set excel type
	//console.debug(id+"="+fldmeta_prop.gridconf.idx.value+"="+(propconf.cellType || "ed"));
	if (propconf.cellType) {
		if (typeof(propconf.cellType)=="string") {
			fmdc.grid_prop.setCellExcellType(id, fldmeta_prop.gridconf.idx.value, propconf.cellType || "ed");
			"ro"==propconf.cellType && fmdc.grid_prop.cells(id, fldmeta_prop.gridconf.idx.value).setBgColor("#F8F8F8");
		} else if (typeof(propconf.cellType)=="object") {
			if ("coro"==propconf.cellType.type) {
				var options1 = typeof(propconf.cellType.options)=='function' ? propconf.cellType.options() 
						: (typeof(propconf.cellType.options)=="string" ? eval(propconf.cellType.options) : propconf.cellType.options);
				if (propconf.cellType.readOnly) {
					fmdc.grid_prop.setCellExcellType(id, fldmeta_prop.gridconf.idx.value, "rocoro");
					fmdc.grid_prop.cells(id, fldmeta_prop.gridconf.idx.value).setOptions(options1);
					propconf.cellType.optionWidth && fmdc.grid_prop.cells(id, fldmeta_prop.gridconf.idx.value).setOptionWidth(propconf.cellType.optionWidth);
				} else {
					fmdc.grid_prop.grid_bindCombo(id, 
							fldmeta_prop.gridconf.idx.value, 
							options1, 
							{"comboSize":10, "comboWidth":propconf.cellType.optionWidth || 160}, 
							defaultVal);
				}
			} else if ("btnex"==propconf.cellType.type) {
				fmdc.grid_prop.setCellExcellType(id, fldmeta_prop.gridconf.idx.value, propconf.cellType.type);
			} else if ("colist"==propconf.cellType.type) {
				fmdc.grid_prop.setCellExcellType(id, fldmeta_prop.gridconf.idx.value, propconf.cellType.type);
			} else {
				fmdc.grid_prop.setCellExcellType(id, fldmeta_prop.gridconf.idx.value, propconf.cellType.type);
			}
			//set configs if has, some excel type has setConfig function
			propconf.cellType.config && fmdc.grid_prop.cells(id, fldmeta_prop.gridconf.idx.value).setConfig && fmdc.grid_prop.cells(id, fldmeta_prop.gridconf.idx.value).setConfig(propconf.cellType.config);
		}
	}
	//set validate if has
	propconf.validator && typeof(propconf.validator)=='string' && fmdc.grid_prop.cells(id, fldmeta_prop.gridconf.idx.value).setAttribute("validate", propconf.validator);
	//set configs if has, some excel type has setConfig function
	propconf.config && fmdc.grid_prop.cells(id, fldmeta_prop.gridconf.idx.value).setConfig && fmdc.grid_prop.cells(id, fldmeta_prop.gridconf.idx.value).setConfig(propconf.config);
	
	//set value
	fmdc.grid_prop.cells(id, fldmeta_prop.gridconf.idx.value).setValue(defaultVal);
	
	//add sub
	if (propconf.sub) {
		for (var sid in propconf.sub) {
			fpf_parseStyleByCellType(id, sid, propconf.sub[sid]);
		}
		fmdc.grid_prop.openItem(id);
	}
	
	//add conditional-sub and hide
	if (propconf["conditional-sub"]) {
		for (var sid in propconf["conditional-sub"]) {
			for (var ssid in propconf["conditional-sub"][sid]) {
				fpf_parseStyleByCellType(id, ssid, propconf["conditional-sub"][sid][ssid], true);
			}
		}
		//fmdc.grid_prop.cells(id, fldmeta_prop.gridconf.idx.prop).cell.firstChild.firstChild.style.visibility="hidden";
	}
	
	//set tooltip
	propconf.tooltip && $(fmdc.grid_prop.cells(id, fldmeta_prop.gridconf.idx.prop).cell).find("div:nth-child(1)").attr("original-title", propconf.tooltip).tipsy({gravity: 'e'});
	//set row hidden
	//override hide from propconf
	if (typeof(propconf.hide)=='function') {
		hide = hide || propconf.hide();
	} else {
		propconf.hide && (hide=true);
	}
	hide && fmdc.grid_prop.setRowHidden(id, true);
	//var te = new Date();
	//console.debug(id+"---------"+(te.getTime() - ts.getTime()));
}

//add tip row 添加分割提示行
function fpf_addTipRow(rid, text) {
	//如果属性已存在则不需要添加
	if(-1 != fmdc.grid_prop.getRowIndex(rid)) {
		return;
	}
	var rn = fmdc.grid_prop.getRowsNum();
	var prid = fmdc.grid_prop.getRowId(rn-1);
	if (rn && fmdc.grid_prop.getRowAttribute(prid, "isTip")) {//avoid duplicate tip row together
		fmdc.grid_prop.cells(prid, fldmeta_prop.gridconf.idx.prop).setValue(text);
	} else {
		fmdc.grid_prop.addRow(rid, [text, ""]);
		fmdc.grid_prop.setRowAttribute(rid, "displayOnly", true);
		fmdc.grid_prop.setRowAttribute(rid, "isTip", true);
		fmdc.grid_prop.setRowColor(rid, fldmeta_prop.gridconf.tiprowbgcolor);
		fmdc.grid_prop.setCellExcellType(rid, fldmeta_prop.gridconf.idx.prop, "ro");
	}
}

//collect properties values
function fpf_collectValues() {
	var vals = {};
	fmdc.grid_prop.forEachRow(function(id){
		if (!fmdc.grid_prop.getRowAttribute(id, "displayOnly") ) {//不处理"仅显示"的行
			if (fmdc.grid_prop.getRowAttribute(id, "isEvent")) {
				var arguments = "";//get arguments for function signature
				var args = fmdc.grid_prop.cells(id, fldmeta_prop.gridconf.idx.value).getConfig();
				if (args) {
					for (a in args) {
						if (arguments) arguments += ",";
						arguments += a;
					}
				}
				vals[id]={"proptype":"event", 
						"value":fmdc.grid_prop.cells(id, fldmeta_prop.gridconf.idx.value).getValue(),
						"arguments":arguments};
			} else {
				vals[id]=fmdc.grid_prop.cells(id, fldmeta_prop.gridconf.idx.value).getValue();
			}
		}
	});
	//console.debug("fpf_collectValues vals="+JSON.stringify(vals));
	fl.curflow.bpmnConfig[fl.curComp.id] = vals;
}

//load existing properties values
function fpf_loadExisting(elemid) {
	var existingConf = fl.curflow.bpmnConfig[elemid];
	//console.debug("existingConf="+JSON.stringify(existingConf));
	if (existingConf) {
		for (var id in existingConf) {//循环设置值
			//console.debug(id + "==" + existingConf[id]);
			//only set existing properties that are available at this time
			if (fmdc.grid_prop.doesRowExist(id)) {
//				if (typeof(existingConf[id])=='object' && existingConf[id].proptype=="event") {
//					fmdc.grid_prop.cells(id, fldmeta_prop.gridconf.idx.value).setValue(existingConf[id].value || "");
//				} else {
					fmdc.grid_prop.cells(id, fldmeta_prop.gridconf.idx.value).setValue(existingConf[id]);
//				}
			} else {
				//TODO should we delete property that will not be used anymore?
			}
		}
	}
}

//do apply
/*function fpf_apply() {
	if (!fpf_validate()) {
		var msg = fmd_i18n_prop_msg_validatefail +'<br/>';
		if (fmdc.proptemp.vfailure) {
			for (var rid in fmdc.proptemp.vfailure) {
				msg += '<br/>' + fmdc.proptemp.vfailure[rid];
			}
		}
		dhtmlx.message(msg);
		return false;
	}
	fpf_collectValues();
	console.debug("fpf_apply fmdc.proptemp="+JSON.stringify(fmdc.proptemp));
	fldmeta_prop[fmdc.proptemp["compType"]][fmdc.proptemp["type"]].onApply && fldmeta_prop[fmdc.proptemp["compType"]][fmdc.proptemp["type"]].onApply();
	fl.unSavedChange = true;
	return true;
}*/

//do validation
function fpf_validate() {
	var result = true;
	fmdc.grid_prop.forEachRow(function(rid) {
		if (!fmdc.grid_prop.isRowHidden(rid)
				 && !fmdc.grid_prop.getRowAttribute(rid, "displayOnly")
				 && false === fmdc.grid_prop.validateCell(rid, fldmeta_prop.gridconf.idx.value)) {
			result = false;
			fmdc.proptemp.vfailure || (fmdc.proptemp.vfailure={});
			fmdc.proptemp.vfailure[rid] = this.cells(rid, fldmeta_prop.gridconf.idx.prop).getValue();
		} else {
			fmdc.proptemp.vfailure && (delete fmdc.proptemp.vfailure[rid]);
		}
	});
	//result && (delete fmdc.proptemp.vfailure);
	return result;
}

//bind events for prop grid
function fpf_bindGridEvents(events) {
	//bind validation event at first
	//fmdc.grid_prop.attachEvent("onValidationError", fpf_onValidationError);
	//fmdc.grid_prop.attachEvent("onLiveValidationError", fpf_onValidationError);
	//fmdc.proptemp.propDhxGridEvents = [];
	
	//绑定预设的事件监听
	if (fldmeta_prop.propDhxGridPredefinedEvents) {
		for (var e in fldmeta_prop.propDhxGridPredefinedEvents) {
			fmdc.grid_prop.attachEvent(e, fldmeta_prop.propDhxGridPredefinedEvents[e]);
			//fmdc.proptemp.propDhxGridEvents.push(e);
		}
	}
	//绑定事件监听
	if (events) {
		for (var e in events) {
			fmdc.grid_prop.attachEvent(e, events[e]);
			//fmdc.proptemp.propDhxGridEvents.push(e);
		}
	}
}

//unbind events for prop grid
function fpf_unbindGridEvents() {
	/*console.debug("fmdc.proptemp.propDhxGridEvents="+JSON.stringify(fmdc.proptemp.propDhxGridEvents));
	if (!fmdc.proptemp.propDhxGridEvents) return;
	for (var e in fmdc.proptemp.propDhxGridEvents) {
		fmdc.grid_prop.detachEvent(fmdc.proptemp.propDhxGridEvents[e]);
	}*/
	fmdc.grid_prop.detachAllEvents();
}

//判断是否显示 条件子属性行
function fpf_showConditionalSub(rId, nv, propconf) {
	//console.debug("rId="+rId+" nv="+nv+" propconf="+JSON.stringify(propconf));
	if (fmdc.grid_prop.getRowById(rId).style.display!="none" && propconf["conditional-sub"]) {
		/*for (var id in propconf["conditional-sub"][nv]) {
			fmdc.grid_prop.setRowHidden(id, false);
		}*/
		/*fmdc.grid_prop.forEachRow(function(id) {
			fmdc.grid_prop.setRowHidden(id, !propconf["conditional-sub"][nv][id]);
		});*/
		var hasSub = false;
		var sids = fmdc.grid_prop.getSubItems(rId);
		if (sids) {
			var sida = sids.split(",");
			if (sida && sida.length>0 && ""!=sida[0]) {
				for (var i in sida) {
					var show = propconf["conditional-sub"][nv] && propconf["conditional-sub"][nv][sida[i]];
					fmdc.grid_prop.setRowHidden(sida[i], !show);
					if (show) {
						hasSub = true;
						fpf_showConditionalSub(sida[i], fmdc.grid_prop.cells(sida[i], fldmeta_prop.gridconf.idx.value).getValue(), JSONSelect.match("."+sida[i], propconf)[0]);
					} else {
						//hide all sub rows
						var subsubs = fmdc.grid_prop.getAllSubItems(sida[i]).split(",");
						if (subsubs && subsubs.length>0 && ""!=subsubs[0]) {
							subsubs.forEach(function(ssid) {
								fmdc.grid_prop.setRowHidden(ssid, true);
							});
						}
					}
				}
			}
			//hasSub && fmdc.grid_prop.closeItem(rId);
		}
		hasSub && fmdc.grid_prop.openItem(rId);
	}/* else {
		var sids = fmdc.grid_prop.getSubItems(rId);
		if (sids) {
			var sida = sids.split(",");
			for (var i in sida) {
				fmdc.grid_prop.setRowHidden(sida[i], true);
			}
			fmdc.grid_prop.closeItem(rId);
		}
	}*/
}

//scroll to row of specified prop
function fpf_scrollToProp(prop) {
	fmdc.grid_prop.selectRowById(prop,false,true);
}

//on vlidation fail
/*function fpf_onValidationError(rid,cid,v) {
	fmdc.proptemp.vfailure || (fmdc.proptemp.vfailure={});
	fmdc.proptemp.vfailure[rid] = this.cells(rid, fldmeta_prop.gridconf.idx.prop).getValue();
}*/

//function fpf_enableApply(enable) {
	/*enable ? fl.cell_prop_tb.enableItem('fp_cb_apply'):
		fl.cell_prop_tb.disableItem('fp_cb_apply');*/
//}

//update property value of current component
function fpf_updateValue(id,val) {
	fl.curflow.bpmnConfig[fl.curComp.id] && (fl.curflow.bpmnConfig[fl.curComp.id][id]=val);
}

//get property value of current component
function fpf_getValue(id) {
	return fl.curflow.bpmnConfig[fl.curComp.id][id];
}


